#include<bits/stdc++.h>
#define int long long
#define N 100005
using namespace std;

int n, m, Q, ans;
int c[N];
int a[N][7], s[N][7], t[7];

int Sol(int l, int r) {
	for(int i = 1; i <= m; i++) t[i] = -1e15;
	t[c[l]] = -s[l - 1][c[l]];
	int res = 0;
	for(int i = l; i <= r; i++) {
		res = t[c[i]] + s[i][c[i]];
		t[c[i + 1]] = max(t[c[i + 1]], res - s[i][c[i + 1]]);
	}
	return res;
}
signed main() {
	freopen("paint.in", "r", stdin);
	freopen("paint.out", "w", stdout);
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);

	cin >> n >> m >> Q;
	for(int i = 1; i <= n; i++) cin >> c[i];
	for(int i = 1; i <= n; i++)
	for(int j = 1; j <= m; j++) {
		cin >> a[i][j];
		s[i][j] = a[i][j] + s[i - 1][j];
	}
	ans = Sol(1, n);
	cout << ans << endl;
	while(Q--) {
		int opt, p, q;
		cin >> opt >> p >> q;
		p ^= ans; q ^= ans;
		if(opt == 1) c[p] = q;
		else {
			ans = Sol(p, q);
			cout << ans << endl;
		}
	}
	return 0;
}

/*
3 2 4
2 1 2
4 4
2 4
3 1

2 8 10
1 11 8
2 10 10
1 0 0
*/
